/**
 * Created by LeungZ on 2016/3/22.
 */
class UserSrv {
    constructor(commonSrv) {
        "ngInject";
        this._commonSrv = commonSrv;
    }

    login(para) {
        return this._commonSrv('form', '/ctg-imageconsole-web/login', {
            username: para.username,
            password: para.password
        });
    }
 
    logOut(){
        return this._commonSrv('get', '/ctg-imageconsole-web/logout');
    }

    getUserInfo(){
        return this._commonSrv('get', '/ctg-imageconsole-web/permission/user')
    }

    getMenu(){
        return this._commonSrv('get','/ctg-imageconsole-web/permission/permission')
    }
    // getMenu(){
    //     return this._commonSrv('get','/ctg-imageconsole-web/permission/menu_tree')
    // }
    
   //获取当前所有用户
    getUserList(page, filter){
        return this._commonSrv('get','/ctg-imageconsole-web/users',{
            pageNum: page.currentPage,
            pageSize: 10,
            userCode: filter && filter.userCode
        })
    }

    addUser(para){
        return this._commonSrv('post','/ctg-imageconsole-web/users' , {
            password: para.password,
            userCode: para.userCode,
            userName: para.userName
        })
    }

    editPassWord(para) {
        return this._commonSrv('put', '/ctg-imageconsole-web/users/'+para.id+'/password',{
            newPassword : para.newPassword,
            oldPassword : para.oldPassword
        })
    }

    getUserItem(id){
        return this._commonSrv('get', '/ctg-imageconsole-web/users/'+id)
    }

    checkUserCode(code){
        return this._commonSrv('get', '/ctg-imageconsole-web/users/userCodeExists',{
            userCode : code
        })
    }

    deleteUser(id){
        return this._commonSrv('delete', '/ctg-imageconsole-web/users/'+id)
    }
}
export default UserSrv